﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

public partial class UserControls_Leftmenu : System.Web.UI.UserControl
{
  protected void Page_Load(object sender, EventArgs e)
  {
    secondaryMenu.Visible = HttpContext.Current.User.Identity.IsAuthenticated ? true : false;
    if (secondaryMenu.Visible)
    {
      liAccount.Attributes["class"] = SetActiveLink("Konto");
      liStockAnalysis.Attributes["class"] = SetActiveLink("Aktieanalyser");
    }
  }

  protected void linkLogOut_Click(object sender, EventArgs e)
  {
    FormsAuthentication.SignOut();
    Response.Redirect("/");
  }

  private string SetActiveLink(string page)
  {
    string url = Request.RawUrl.ToString().ToLower();
    string[] partUrl = url.Split('/'); //Splits URL at /
    return partUrl[1].Equals(page.ToLower()) ? "current" : string.Empty;
  }
}